# -*- coding: utf-8 -*-
'''
@Time    : 24-5-24 下午15:37
@Author  : zhangweihao
@File    : tasks.py
'''
import json
import logging
import os
import sys
import time

from celery_task.main import celery
from searcher import Searcher


@celery.task()
def build_index_one(file_path):
    searcher = Searcher()
    searcher.index_documents_one(file_path)


@celery.task()
def build_index_all(file_path):
    with open('./config.json', 'r') as f:
        data = json.load(f)
    searcher = Searcher()
    start_time = time.time()
    searcher.index_documents_all(file_path)
    end_time = time.time()
    logging.info('耗时:')
    logging.info(end_time - start_time)
    data['building_index'] = 0
    with open('./config.json', 'w') as f:
        json.dump(data, f, indent=4)
